#! /user/bin/env python
#coding:utf-8

import pymongo
import time
import datetime


addr = "127.0.0.1:27017"

account = "admin"
password = "123456"

def collection_find():
        db_name = "yange_data"
        myclient = pymongo.MongoClient("mongodb://" + addr + "/")
        dblist = myclient.list_database_names()
        if db_name in dblist:
                mydb = myclient[db_name]
                mydb.authenticate(account, password)
                tblist = mydb.list_collection_names()
                doc = mydb["users"]
                data_list = doc.find()
                for data in data_list:
                        if data.has_key('coins'):
                                print data['uid'], data['coins'], type(data)
                                del data['coins']
				myquery = {"_id": data["_id"]}
				newvalue = {"$unset": {"coins":{"$gt":0}}}
                                res = doc.update(myquery,newvalue, upsert=True)
				print res
print "mongo 操作"
collection_find()

